local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.BaseComponent());
local CallBackManager = ClientOHOH.load.CallBackManager();
local UIManager = ClientOHOH.load.UIManager();
local BattleHomeGui=UIManager:CreateUI("BattleHomeGui",require(script.BattleHomeGui))
local BigNumberHelper = ClientOHOH.load.BigNumberHelper();
local CodeAnimationTool=_G.CommonOHOH.load.CodeAnimationTool();
local GlobalTipGui = ClientOHOH.load.UIManager().ui_list.GlobalTipGui;
local LanguageHelper= _G.LanguageHelper
local Game_Cfg=ClientOHOH.config.Game

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);

	self.HomeCtrl=self.parent:GetComponent(ClientOHOH.load.Client_HomeCtrl());

	self.dataBase=self.parent:GetComponent(ClientOHOH.load.Client_PlayerDataComponent());

	BattleHomeGui:SetAutoAttack(false)

	self.parent.AutoAttckEvent:Connect(function(isAuto)
		BattleHomeGui:SetAutoAttack(isAuto)
	end)

	self.parent.BattleSateEvent:Connect(function(isBattle)
		if isBattle then
			self:Show()
			self.HomeCtrl:Hide()
		else
			self.HomeCtrl:Show()
			self:Hide()
		end
	end)
	
	self:InitGoShow()

	self:Hide()

end;

function M.InitGoShow(self)

	--宠物
	CallBackManager:AddRbxConnect(self,BattleHomeGui.insts.pet.button.Activated, function()
		UIManager.ui_list.PetGui:Show()
		UIManager.ui_list.HomeGui:SetPetRed()
	end);

	--武器
	CallBackManager:AddRbxConnect(self,BattleHomeGui.insts.weapon.button.Activated, function()
		UIManager.ui_list.WeaopnEquipGui:Show()
		UIManager.ui_list.HomeGui:SetWeaponRed()
	end);
	

	-- 重生
	CallBackManager:AddRbxConnect(self,BattleHomeGui.insts.Rebirth.button.Activated, function()
        -- UIManager.ui_list.BuffGuiRebirthGui:Show()
		UIManager.ui_list.RebirthGuiNew:Show()
	end);

	-- 好友显示
	CallBackManager:AddRbxConnect(self,BattleHomeGui.insts.FriendEquip.button.Activated, function()
		UIManager.ui_list.HomeGui:SetFriendEquipRed()
		UIManager.ui_list.BroGui:Show()
	end);

	--自动攻击
	CallBackManager:AddRbxConnect(self,BattleHomeGui.insts.auto_attack.button.Activated, function()
		if not self.parent.character then
			return
		end
		assert(self.parent.character,"self.parent.character==NULL")
		self.parent:ChangeAutoAttackState()
	end);

	-- 邀请好友
	CallBackManager:AddRbxConnect(self,BattleHomeGui.insts.Friend.button.Activated, function()
		self.HomeCtrl:InviteFriend()
    end);

	--跳转到加点数
	CallBackManager:AddRbxConnect(self,BattleHomeGui.insts.property.button.Activated, function()

		UIManager.ui_list.PointGui:Show()
	end);


	
	-- 交易界面
	CallBackManager:AddRbxConnect(self,BattleHomeGui.insts.Trade.button.Activated, function()
			
		if self.dataBase:GetData("base").level<Game_Cfg.TradeUnLockLevel then
			GlobalTipGui:Show(LanguageHelper:GetText(30041,{"%%ARG1"},{Game_Cfg.TradeUnLockLevel}))
		else
			UIManager.ui_list.TradeSendMsgGui:Show()
		end
	end);



end


function M.AddBaseItem(self,itemId,WorldPosList,count)
	local uiId=itemId
	local effectId="Effect.fly_"..itemId
	local uipos,uisize= BattleHomeGui:GetItemAbsoluteProperties(uiId)

	for _,pos in pairs(WorldPosList) do
		CodeAnimationTool.UiAnimation.world2Screen(function()
			return _G.POOL:GetObj(effectId)
		end,function(e)
			_G.POOL:PushObj(effectId,e)
			BattleHomeGui:AddItem(uiId,count)
		end,pos,uipos,uisize)
	end
end

function M.Show(self)
	BattleHomeGui:Show()
end

function M.Hide(self)
	BattleHomeGui:Hide()
end

function M.dtor(self)
	M.super.dtor(self);
end;


return M